package com.atguigu.ssyx.commom.exception;

import com.atguigu.ssyx.commom.result.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author ZhangYK
 * @version 8.0
 * @title GlobalExceptionHandler
 * @description
 * @create 2024/7/5 10:00
 */
@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public Result error(Exception e) {
        e.printStackTrace();
        return Result.fail(null);
    }

    /**
     * 自定义异常处理方法
     * @param ssyxException
     * @return
     */
    @ExceptionHandler(value = SsyxException.class)
    @ResponseBody
    public Result error(SsyxException ssyxException){
        return Result.build(null, ssyxException.getCode(),ssyxException.getMessage());
    }
}
